package edu.gatech.geochat;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class BetterActivity extends Activity {
	
	public void onCreate(Bundle b) {
		super.onCreate(b);
		GUISpace.put(GeoChatActivity.class, "ActiveActivity", this);
	}
	
	public void onDestroy() {
		super.onDestroy();
		if (isFinishing()) {
			Log.d("CleanActivity", "Clearing prefixes for \"" + getClass().getName() + "\"");
			GUISpace.clearPrefix(getClass());
		}
	}
	
	@Override
	public void onResume() {
		super.onResume();
		setStatusText(GUISpace.getString(getClass(), "status"), false);
	}
	
	public void setStatusText(String text) {
		setStatusText(text, true);
	}
	
	private void setStatusText(final String text, boolean updateSpace) {
		if (updateSpace)
			GUISpace.put(getClass(), "status", text);
		View view = findViewById(R.id.statusText);
		if (view != null) {
			final TextView tv = (TextView) view;
			((TextView)view).post(new Runnable() {
				public void run() {
					tv.setText(text);
				}
			});
		}
	}
}
